/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import koneksi.CekKoneksi;

/**
 *
 * @author priska
 */
public class beanBarang {

    private Connection conn;

    public beanBarang(Connection koneksi) {
        this.conn = koneksi;
    }

    public static beanBarang getKoneksi() throws SQLException {
        beanBarang kon = new beanBarang(CekKoneksi.open());

        return kon;
    }

    public void updateBarang(Barang brg) throws SQLException {
        Connection con = CekKoneksi.open();
        Statement st = null;
        ResultSet rs = null;

        Double harga = brg.getHargaBarang();
        String kode = brg.getKodeBarang();
        st = conn.createStatement();
        String sql = "update cabanga set harga_barang =" + harga + "where kode_barang ='" + kode + "'";
        String sql2 = "update cabangb set harga_barang =" + harga + "where kode_barang ='" + kode + "'";
        String sql3 = "update cabangc set harga_barang =" + harga + "where kode_barang ='" + kode + "'";
        st.executeUpdate(sql);
        st.executeUpdate(sql2);
        st.executeUpdate(sql3);
        conn.close();



    }

    public void tambahStock(Barang brg) throws SQLException {
        Connection con = CekKoneksi.open();
        Statement st = null;
        ResultSet rs = null;
        Login log = new Login();
        String area = brg.getArea().getCabang();
        int jumlah = brg.getJumlahBarang();
        Double harga = brg.getHargaBarang();
        String nama = brg.getNamaBarang();
        String kode = brg.getKodeBarang();
        st = conn.createStatement();
        String sql = "update " + area + " set Jumlah = jumlah+" + jumlah + " where kode_barang = '" + kode + "'";
        st.executeUpdate(sql);
        conn.close();
    }
}